﻿#include "CTPLoginAccount.h"


CTPLogin::AccountBase::AccountBase(const QString &pSetingFile)
{
	m_setting = new QSettings(pSetingFile, QSettings::IniFormat);
}

CTPLogin::AccountBase::~AccountBase()
{
	m_setting->deleteLater();
}

void CTPLogin::AccountBase::SetBrokerID(const QString &pVal)
{
	m_setting->setValue("BrokerID", pVal);
}

std::string CTPLogin::AccountBase::GetBrokerID()
{
	QString brokerId = m_setting->value("BrokerID").toString();
	return brokerId.toLocal8Bit().data();
}

void CTPLogin::AccountBase::SetUserID(const QString &pVal)
{
	m_setting->setValue("UserID", pVal);
}

std::string CTPLogin::AccountBase::GetUserID()
{
	QString pval = m_setting->value("UserID").toString();
	return pval.toLocal8Bit().data();
}

void CTPLogin::AccountBase::SetPassword(const QString &pVal)
{
	m_setting->setValue("Password", pVal);
}

std::string CTPLogin::AccountBase::GetPassword()
{
	QString pval = m_setting->value("Password").toString();
	return pval.toLocal8Bit().data();
}

void CTPLogin::AccountBase::SetUrlList(const QStringList &pList)
{
	QString purlStr = pList.join(';');
	m_setting->setValue("UrlList", purlStr);
}

void CTPLogin::AccountBase::GetUrlList(std::list<std::string> &outUrlList)
{
	QString pval = m_setting->value("UrlList").toString();
	if (pval.isEmpty())
	{
		return;
	}
	QStringList valList = pval.split(';');
	for (QStringList::iterator it = valList.begin(); it != valList.end(); ++it)
	{
		std::string url = it->toLocal8Bit().data();
		outUrlList.emplace_back(url);
	}
}

CTPLogin::MDAccount::MDAccount(const QString &pSetingFile)
	:AccountBase(pSetingFile)
{
}

CTPLogin::TradeAccount::TradeAccount(const QString &pSetingFile)
	: AccountBase(pSetingFile)
{
}

void CTPLogin::TradeAccount::SetAuthCode(const QString &pVal)
{
	m_setting->setValue("AuthCode", pVal);
}

std::string CTPLogin::TradeAccount::GetAuthCode()
{
	QString pval = m_setting->value("AuthCode").toString();
	return pval.toLocal8Bit().data();
}

void CTPLogin::TradeAccount::SetProductInfo(const QString &pVal)
{
	m_setting->setValue("ProductInfo", pVal);
}

std::string CTPLogin::TradeAccount::GetProductInfo()
{
	QString pval = m_setting->value("ProductInfo").toString();
	return pval.toLocal8Bit().data();
}

void CTPLogin::TradeAccount::SetAppID(const QString &pVal)
{
	m_setting->setValue("AppID", pVal);
}

std::string CTPLogin::TradeAccount::GetAppID()
{
	QString pval = m_setting->value("AppID").toString();
	return pval.toLocal8Bit().data();
}

void CTPLogin::TradeAccount::SetInvestorID(const QString &pVal)
{
	m_setting->setValue("InvestorID", pVal);
}

std::string CTPLogin::TradeAccount::GetInvestorID()
{
	QString pval = m_setting->value("InvestorID").toString();
	return pval.toLocal8Bit().data();
}
